package com.cy.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class LoadBlancedController {
    @Value("${spring.application.name}")
    private String applicationName;
    @Autowired
    private RestTemplate loadBalancedRestTemplate;

    @GetMapping("/consumer/doRestEcho/")
    public String doBalance(){
        String url=String.format("http://%s/provider/doecho/%S", "nacos-provider",applicationName);
        return loadBalancedRestTemplate.getForObject(url,String.class);
    }
}
